<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>学生信息管理</title>
<script type="text/javascript">
	
	function delDish(){
		//获得选中数据对象
		var selectedRows=$("#dg").datagrid('getSelections');
		if(selectedRows.length==0){
			$.messager.alert("系统提示","请选择要删除的数据！");
			return;
		}
		var strIds=[];//要删除的序号组合
		for(var i=0;i<selectedRows.length;i++){
			strIds.push(selectedRows[i].dishid);
		}
		var ids=strIds.join(",");
		$.messager.confirm("系统提示","您确认要删掉这<font color=red>"+selectedRows.length+"</font>条数据吗？",function(r){
			if(r){
				//ajax提交 delIds
				$.post("delDishList",{dishids:ids},function(result){
					if(result){
						$.messager.alert("系统提示","您已成功删除<font color=red>"+selectedRows.length+"</font>条数据！");
						$("#dg").datagrid("reload");
					}else{
						$.messager.alert('系统提示',"删除失败");
					}
				},"json");
			}
		});
	}
	
	//查询符合条件的用户
	function searchDish(){
		$('#dg').datagrid('load',{
			dishid:$('#dishid').val(),
			dishname:$('#dishname').val(),
			dishintro:$('#dishintro').val(),
			dishcookway:$('#dishcookway').val()
		});
	}
	function openDishModifyDialog(){
		var selectedRows=$("#dg").datagrid('getSelections');
		if(selectedRows.length!=1){
			$.messager.alert("系统提示","请选择一条要编辑的数据！");
			return;
		}
		var row=selectedRows[0];
		$("#dlg").dialog("open").dialog("setTitle","编辑菜品资料");
		$("#mdishid").val(row.dishid);
		$("#mdishname").val(row.dishname);
		$("#mdishintro").val(row.dishintro);
		$("#mdishprice").val(row.dishprice);
		$("#mdishcookway").val(row.dishcookway)
	}	
	function saveDish(){
		$("#fm").form("submit",{
			url:"updateDish",
			onSubmit:function(){
				
				if($('#mdishname').val()==""){
					$.messager.alert("系统提示","请输入菜品名");
					return false;
				}
				if($('#mdishintro').val()==""){
					$.messager.alert("系统提示","请输入菜品介绍");
					return false;
				}
				if($('#mdishprice').val()==""){
					$.messager.alert("系统提示","请输入菜品价格");
					return false;
				}if($('#mdishcookway').val()==""){
					$.messager.alert("系统提示","请输入做菜方式");
					return false;
				}
				return $(this).form("validate");
			},
			success:function(result){
				if(result){
					$.messager.alert("系统提示","保存成功");
					$("#dlg").dialog("close");
					$("#dg").datagrid("reload");
				}else{
					$.messager.alert("系统提示","保存失败");
					return;
				}
			}
		});
	}
	
	function exportAdmin(){
		var selectedRows=$("#dg").datagrid('getSelections');
		var strIds=[];//要删除的序号组合
		var ids=null;
		if(selectedRows.length !=0){
			for(var i=0;i<selectedRows.length;i++){
				strIds.push(selectedRows[i].dishid);
			}
				 ids=strIds.join(",");
		}
		//注意js中null的传递,null传到服务器后就是'null'字符串,并不是真正的null(please careful)
		if(ids==null){
			window.open("exportDish");
		}
		else{
			window.open("exportDish?dishids="+ids);  
		}
	}
	//关闭对话框
	function closeDishDialog(){
		$("#dlg").dialog("close");
	}
</script>
<link rel="stylesheet" type="text/css"  href="../easyui-1.5/themes/default/easyui.css" />
<link rel="stylesheet" type="text/css"  href="../easyui-1.5/themes/icon.css" />
<script type="text/javascript" src="../easyui-1.5/jquery.min.js"></script>
<script type="text/javascript" src="../easyui-1.5/jquery.easyui.min.js"></script>
<script type="text/javascript" src="../easyui-1.5/locale/easyui-lang-zh_CN.js"></script>
</head>
<body style="margin:5px">
	<table id="dg" title="菜品信息" class="easyui-datagrid" fitColumns="true" striped="true"
	 pagination="true" rownumbers="true" url="getDishList" fit="true" toolbar="#tb" datapagesize="5">
		<thead>
			<tr>
				<th field="cb" checkbox="true"></th>
				<th field="dishid" width="50" align="center">菜品id</th>
				<th field="dishimapath" width="100" align="center" >菜品图片</th>				
				<th field="dishname" width="100" align="center">菜品名称</th>
				<th field="dishintro" width="100" align="center">菜品介绍</th>
				<th field="dishprice" width="100"  align="center">菜品价格</th>
				<th field="dishcookway" width="100"  align="center">做菜方式</th>
			</tr>
		</thead>
	</table>
	<div id="tb">
		<div>
			<a href="javascript:openDishModifyDialog()" class="easyui-linkbutton" iconCls="icon-edit" plain="true">修改</a>
			<a href="javascript:delDish()" class="easyui-linkbutton" iconCls="icon-remove" plain="true">删除</a>
			<a href="javascript:exportAdmin()" class="easyui-linkbutton" iconCls="icon-redo" plain="true">导出Execl</a>
		</div>
		<div>
			<form id="export" method="post">
			&nbsp;菜品id：&nbsp;<input type="text" name="dishid" id="dishid" size="10"/>
			&nbsp;菜品名称：&nbsp;<input type="text" name="dishname" id="dishname" size="10"/>
			&nbsp;菜品介绍：&nbsp;<input type="text" name="dishintro" id="dishintro" size="10" data-options="validType:'number'"/>
			&nbsp;做菜方式：&nbsp;<input type="text" name="dishcookway" id="dishcookway" size="10"/>
			<a href="javascript:searchDish()" class="easyui-linkbutton" iconCls="icon-search" plain="true">搜索</a>
			</form>
		</div>
	</div>
	
	<div id="dlg" class="easyui-dialog" style="width: 550px;height: 240px;padding: 10px 20px"
		closed="true" buttons="#dlg-buttons">
		<form id="fm" method="post">
			<table cellspacing="5px;">
				<tr>		
					<td>菜品id：</td>
					<td><input type="text" name="dishid" id="mdishid" class="easyui-validatebox" required="true" readonly/></td>
					<td>菜品名称：</td>
					<td><input type="text" name="dishname" id="mdishname" class="easyui-validatebox" required="true"/></td>
				</tr>
				<tr>
					<td>菜品介绍：</td>
					<td><input type="text" name="dishintro" id="mdishintro" class="easyui-validatebox" required="true"/></td>
					<td>菜品价格：</td>
					<td><input type="text" name="dishprice" id="mdishprice" class="easyui-validatebox" data-options="required:true,validType:'number'"/></td>
				</tr>
				<tr>
					<td>做菜方式:</td>
					<td><input type="text" name="dishcookway" id="mdishcookway" class="easyui-validatebox" data-options="required:true"/></td>
				</tr>
			</table>
		</form>
	</div>
	
	<div id="dlg-buttons">
		<a href="javascript:saveDish()" class="easyui-linkbutton" iconCls="icon-ok">保存</a>
		<a href="javascript:closeDishDialog()" class="easyui-linkbutton" iconCls="icon-cancel">关闭</a>
	</div>
	
</body>
</html>